package com.winsdom.entity.customer;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
@Schema(name = "CustomerEnterpriseBasicInfoResponse", description = "企业客户基础信息响应")
public class CustomerEnterpriseBasicInfoResponse {

    @Schema(description = "客户ID", example = "34")
    private Long customerId;

    @Schema(description = "客户类型", example = "1")
    private Integer customerType;

    @Schema(description = "客户名称", example = "最新的企业8")
    private String customerName;

    @Schema(description = "联系电话", example = "19942888888")
    private String mobilePhone;

    @Schema(description = "统一社会信用代码", example = "96678900ILHRW8888")
    private String unifiedSocialCreditCode;

    @Schema(description = "企业性质", example = "合资")
    private String enterpriseNature;

    @Schema(description = "业务性质", example = "农业")
    private String businessNature;

    @Schema(description = "电子邮箱", example = "updated888888@example.com")
    private String email;

    @Schema(description = "税务身份", example = "Small-scale taxpayer")
    private String taxIdentity;

    @Schema(description = "是否重点投资客户", example = "No")
    private String keyInvestmentCustomer;

    @Schema(description = "开户银行名称", example = "Bank of China")
    private String bankName;

    @Schema(description = "银行账号", example = "88888888888888")
    private String bankAccount;

    @Schema(description = "注册资本", example = "188888888.00")
    private BigDecimal registeredCapital;

    @Schema(description = "员工数量", example = "110")
    private Integer numberOfPeople;

    @Schema(description = "营业执照图片路径", example = "/images/business_license8.jpg")
    private String businessLicenseImage;

    @JsonIgnore
    private AddressInfo registrationAddress;

    @JsonIgnore
    private AddressInfo officeAddress;

    @Schema(description = "联系人信息列表")
    private List<ContactInfo> contactInfos;

    @Data
    @Schema(name = "AddressInfo", description = "地址信息")
    public static class AddressInfo {
        @Schema(description = "地址类型（1-注册地址，2-办公地址）", example = "1")
        private Integer addressType;

        @Schema(description = "区域", example = "[\"浙江省\", \"杭州市\", \"西湖区\"]")
        private String area;

        @Schema(description = "区域码", example = "[\"33\", \"3301\", \"330106\"]")
        private String areaCode;

        @Schema(description = "详细地址", example = "Chongqing City, Detailed Address 1")
        private String detailedAddress;
    }

    @Data
    @Schema(name = "ContactInfo", description = "联系人信息")
    public static class ContactInfo {
        @Schema(description = "联系人ID", example = "1")
        private Long contactId;

        @Schema(description = "联系人姓名", example = "刘东")
        private String contactName;

        @Schema(description = "联系电话", example = "13567645888")
        private String contactMobile;

        @Schema(description = "邮箱", example = "liudong1@example.com")
        private String contactEmail;

        @Schema(description = "接收的楼盘分类列表", example = "[\"金星大厦\"]")
        private List<String> receiveProperties;
    }

    @JsonProperty("addresses")
    public List<AddressInfo> getAddresses() {
        List<AddressInfo> addresses = new ArrayList<>();
        if (registrationAddress != null) {
            registrationAddress.setAddressType(1);
            addresses.add(registrationAddress);
        }
        if (officeAddress != null) {
            officeAddress.setAddressType(2);
            addresses.add(officeAddress);
        }
        return addresses;
    }

    @JsonIgnore
    public void setRegistrationAddress(AddressInfo registrationAddress) {
        this.registrationAddress = registrationAddress;
    }

    @JsonIgnore
    public void setOfficeAddress(AddressInfo officeAddress) {
        this.officeAddress = officeAddress;
    }
}